(function() {
    'use strict';

    /** 预约项目类型管理
     * @ngdoc function
     * @name webApp.controller:GzhsctagCtrl
     * @description 
     * # GzhsctagCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('GzhsctagCtrl', GzhsctagCtrl);

    GzhsctagCtrl.$inject = ['$scope', 'dataService', 'helper', 'dhfprinterService', '$timeout', '$interval', '$rootScope', '$state', 'moment', '$location'];

    function GzhsctagCtrl($scope, dataService, helper, dhfprinterService, $timeout, $interval, $rootScope, $state, moment, $location) {
        $scope.listAction = function() {
            $scope.getlist(1);
            $scope.pageSize =10;
        }

        $scope.getlist = function(pageNo) {
            $scope.pageNo = pageNo ? pageNo : "1";
            var query = {
                content: {
                    page_no: $scope.pageNo,
                    page_size: $scope.pageSize,
                }
            };
            dataService.gzhsutagGet(query).then(function(re1) {
                if (re1.gzhsc_tag_list) {
                    $scope.gzhsc_tag_list = re1.gzhsc_tag_list;
                    $scope.total_count = re1.total_count;
                }
            });
        }

        $scope.getone = function() {
            var query = {
                content: { gzhsc_tag_id: $scope.gzhsc_tag_id }
            };
            dataService.gzhsutagGet(query).then(function(re1) {
                if (re1.gzhsc_tag_list) {
                    $scope.tag = re1.gzhsc_tag_list[0];
                    console.error("gzhsc_cat_id", $scope.tag);
                }
            });
        }


        //添加数据 初始化
        $scope.addAction = function() {
            $scope.gzhsc_tag_id = $location.search().gzhsc_tag_id;
            if ($scope.gzhsc_tag_id) {
                $scope.getone();
            } else {
                $scope.tag = { name: null, gzhsc_tag_id: 0 };
            }
        }

        $scope.operation = function(type, title, id) {
            helper.myConfirm("确定" + title, function() {
                var data = { content: { "gzhsc_tag_id": id } };
                $scope.postapi(type, data);
            });
        }

        $scope.saveData = function() {
            var api = "add";
            var data = {
                content: {
                    "name": $scope.tag.name,
                    "gzhsc_tag_id": $scope.tag.gzhsc_tag_id
                }
            }
            console.error("gzhsc_cat_id", $scope.tag);
            $scope.postapi(api, data);
        }

        $scope.postapi = function(type, data) {
            var zhuoziApiAry = {
                "add": "gzhsutagAdd",
                "del": "gzhsutagDelete",
            }
            dataService[zhuoziApiAry[type]](data).then(function(r) {
                if (r.Msg) {
                    helper.myAlert(r.Msg);
                } else {
                    helper.myAlert("success", null, null, function() {
                        $scope.getlist(1);
                        $state.go("gzhsctag.list");
                    });
                }

            })
        }
    }
})();